import type { Directive, DirectiveBinding } from "vue";

/**
 * 给元素设置指定或随机背景色
 * 随机：v-randomBgColor
 * 指定：v-randomBgColor="'red'"
 */
const randomBgColor: Directive = {
    mounted(el: HTMLElement, binding: DirectiveBinding) {
        el.style.backgroundColor = binding.value ?? `#${Math.floor(Math.random() * 16777215).toString(16)}`;
    }
};

export default randomBgColor;
